﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace 企业门户.App_Start
{
    public class MyAuthorizeAttribute : AuthorizeAttribute
    {
        //验证身份
        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            return httpContext.Session["user"] != null;
        }

        //身份验证不通过时，要如何处理
        protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
        {
            //跳转登录页面
            string url = HttpUtility.UrlEncode(filterContext.HttpContext.Request.Url.ToString());
            filterContext.HttpContext.Response.Redirect("/login?ReturnUrl="+url);
        }
    }
}